﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class TaoBaoApi_TB_DownBaobei : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            new TBCommon().BindTBShop(ddlShop);
            if (ddlShop.Items.Count > 0)
                ddlShop.SelectedIndex = 0;
            BindTypeRoot();
        }
    }    
    //绑定淘宝类目
    void BindTypeRoot()
    {
        List<Model.TaoBao.TB_LEIMU> tbs = new BLL.TaoBao.TB_LEIMU().GetAllList();
        ddlType1.Items.Clear();        
        foreach (Model.TaoBao.TB_LEIMU m in tbs)
            if (m.PARENTID == 0)
                ddlType1.Items.Add(new ListItem(m.LMMC, m.MID.ToString()));
        if (ddlType1.Items.Count > 0)
        {
            ddlType1.SelectedIndex = 0;
            ddlType1_SelectedIndexChanged(null, null);
        }
    }

    /// <summary>
    /// 下载淘宝宝贝
    /// </summary>
    protected void btnDown_Click(object sender, EventArgs e)
    {
        if (ddlShop.SelectedIndex<0)
        {
            new TBCommon().ShowMessage(Page, "请选择淘宝店铺");
            return;
        }
        string name = ddlShop.SelectedItem.Text;
        if (txtType.Text.TrimEnd().Length == 0)
            txtMID.Text = "";
        Response.Redirect("tb_downbaobei2.aspx?user=" + name+"&type="+txtMID.Text+"+&showcase="+radio1.SelectedIndex.ToString());       
    }
    protected void ddlType1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlType1.SelectedIndex > -1)
        {
            List<Model.TaoBao.TB_LEIMU> tbs = new BLL.TaoBao.TB_LEIMU().GetAllList();
            ddlType2.Items.Clear();
            txtMID.Text = "";
            txtType.Text = "";
            foreach (Model.TaoBao.TB_LEIMU m in tbs)
                if (m.PARENTID == Convert.ToInt32(ddlType1.SelectedValue))
                    ddlType2.Items.Add(new ListItem(m.LMMC, m.MID.ToString()));
            if (ddlType2.Items.Count > 0)
            {
                ddlType2.SelectedIndex = 0;
                ddlType2_SelectedIndexChanged(null, null);
            }
            ddlType3.Items.Clear();
            if (ddlType2.Items.Count == 0)
            {
                txtType.Text = ddlType1.SelectedItem.Text;
                txtMID.Text = ddlType1.SelectedValue;
            }
        }
    }
    protected void ddlType2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlType2.SelectedIndex > -1)
        {
            List<Model.TaoBao.TB_LEIMU> tbs = new BLL.TaoBao.TB_LEIMU().GetAllList();
            ddlType3.Items.Clear();
            txtMID.Text = "";
            txtType.Text = "";
            foreach (Model.TaoBao.TB_LEIMU m in tbs)
                if (m.PARENTID == Convert.ToInt32(ddlType2.SelectedValue))
                    ddlType3.Items.Add(new ListItem(m.LMMC, m.MID.ToString()));
            if (ddlType3.Items.Count > 0)
            {
                ddlType3.SelectedIndex = 0;
                ddlType3_SelectedIndexChanged(null, null);
            }
            if (ddlType3.Items.Count == 0)
            {
                txtType.Text = ddlType2.SelectedItem.Text;
                txtMID.Text = ddlType2.SelectedValue;
            }
        }
    }
    protected void ddlType3_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlType3.SelectedIndex > -1)
        {
            txtType.Text = ddlType3.SelectedItem.Text;
            txtMID.Text = ddlType3.SelectedValue;
        }
    }
}
